package com.yc.project1_matrix.individual;

/**
 * 计算result矩阵[i][j]那个元素的值  matrix1对应的 和matrix2的
 */
public class IndividualMultiplier implements Runnable{
    private  final double[][] result;//final:确保线程安全性
    private  final double[][] matrix1;
    private  final double[][] matrix2;
    private final int row;
    private  final int column;

    /**
     *
     * @param result: 结果矩阵
     * @param matrix1：矩阵A
     * @param matrix2: 矩阵B
     * @param row :结果矩阵的第i行
     * @param column ：结果矩阵的第j列
     */
    public IndividualMultiplier(double[][] result, double[][] matrix1, double[][] matrix2, int row, int column) {
        this.result = result;
        this.matrix1 = matrix1;
        this.matrix2 = matrix2;
        this.row = row;
        this.column = column;
    }


    @Override
    public void run() {
        result[row][column]=0;
        //累加求和
        for (int k=0;k<matrix1[row].length;k++) {
            result[row][column] += matrix1[row][k] * matrix2[k][column];
        }
    }







}
